﻿@page "/fileinput"

@using NorthwindBlazor.Data
@using NorthwindBlazor.Models.Northwind

@inject NorthwindContext dbContext

<RadzenExample Name="FileInput">
<div class="row">
    <div class="col-md-6">
        <h3>FileInput</h3>
        <RadzenCard Style="width:600px;margin-bottom: 20px; height:500px;">
            <div class="row">
                <div class="col-md-12">
                    <div style="margin-top:20px">Employee:</div>
                    <b>@(firstEmployee.FirstName + " " + firstEmployee.LastName)</b>
                    <br />
                    <RadzenFileInput @bind-Value="@firstEmployee.Photo" Style="width:400px;" TValue="string" Change="@(args => Change(args, "FileInput"))" />
                </div>
            </div>
        </RadzenCard>
    </div>
    <div class="col-md-6">
        <h3>Events</h3>
        <RadzenCard style="overflow: auto;height:500px;">
            @foreach (var e in events.OrderByDescending(i => i.Key))
            {
                @e.Value
                <br />
            }
        </RadzenCard>
    </div>
</div>
</RadzenExample>

@code {
    Employee firstEmployee;

    protected override async Task OnInitializedAsync()
    {
        firstEmployee = await Task.FromResult(dbContext.Employees.FirstOrDefault());
    }

    Dictionary<DateTime, string> events = new Dictionary<DateTime, string>();

    void Change(string value, string name)
    {
        var str = new string($"{value}".Take(100).ToArray());

        events.Add(DateTime.Now, $"{name} value changed to {str}...");
        StateHasChanged();
    }
}
